package com.socialuni.center.web.controller.login;

import com.socialuni.sdk.api.model.ResultRO;
import com.socialuni.center.web.model.RO.CenterLoginRO;
import com.socialuni.center.web.model.RO.user.CenterMineUserDetailRO;
import com.socialuni.center.web.serive.user.CenterPhoneNumService;
import com.socialuni.center.web.user.login.CenterLoginService;
import com.socialuni.sdk.constant.platform.PlatformType;
import com.socialuni.sdk.model.BindPhoneVO;
import com.socialuni.sdk.model.ProviderLoginQO;
import com.socialuni.sdk.model.QO.phone.BindWxPhoneNumQO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author qinkaiyuan
 * @date 2019-02-17 14:14
 */
@RestController
@RequestMapping("socialuni/user")
@Slf4j
public class UserLoginController {
    @Resource
    private CenterLoginService centerLoginService;
    @Resource
    CenterPhoneNumService centerPhoneNumService;

    @Deprecated
    //三方渠道登录，qq、wx、社交联盟，兼容各平台，h5、app、mp
    @PostMapping("providerLogin")
    @ResponseBody
    public ResultRO<CenterLoginRO<CenterMineUserDetailRO>> providerLogin(@RequestBody ProviderLoginQO loginVO) {
        CenterLoginRO<CenterMineUserDetailRO> socialUserDetailRO = centerLoginService.providerAndPhoneLogin(loginVO, null);
        return new ResultRO<>(socialUserDetailRO);
    }

    @Deprecated
    //可以携带id也可以不携带，不携带返回时生成
    //app端，小程序端，微信和qq登陆的接口，传入第三方返回的基础信息，昵称等，没有手机号，Provider = 'weixin' | 'qq'
    @PostMapping("platformLogin")
    public ResultRO<CenterLoginRO<CenterMineUserDetailRO>> platformLogin(@RequestBody @Valid ProviderLoginQO loginVO) {
        //Provider = 'weixin' | 'qq'
        CenterLoginRO<CenterMineUserDetailRO> socialUserDetailRO = centerLoginService.providerAndPhoneLogin(loginVO, null);
        return new ResultRO<>(socialUserDetailRO);
    }

    @Deprecated
    @PostMapping("phoneLogin")
    @ResponseBody
    public ResultRO<CenterLoginRO<CenterMineUserDetailRO>> phoneLogin(@RequestBody @Valid BindPhoneVO bindPhoneVO) {
        //Provider = 'weixin' | 'qq'
        CenterLoginRO<CenterMineUserDetailRO> socialUserDetailRO = centerLoginService.providerAndPhoneLogin(null, bindPhoneVO);
        return new ResultRO<>(socialUserDetailRO);
    }


    /**
     * 微信小程序界面点击绑定手机号触发
     *
     * @param bindWxPhoneNumQO
     * @return
     */
    @Deprecated
    @PostMapping("bindPhoneNumByWx")
    @ResponseBody
    public ResultRO<CenterMineUserDetailRO> bindPhoneNum(@RequestBody BindWxPhoneNumQO bindWxPhoneNumQO) {
        CenterMineUserDetailRO centerMineUserDetailRO = centerPhoneNumService.userBindWxPhoneNum(bindWxPhoneNumQO);
        return new ResultRO<>(centerMineUserDetailRO);
    }


    /**
     * 登录接口，登录后返回用户的token
     * toDO 还没有做百度和头条平台的适配
     *
     * @param loginVO
     * @return
     */
    @Deprecated
    //下版本作废 2021-7-17，统一使用 login/providerLogin
    @PostMapping("miniAppLogin")
    public ResultRO<CenterLoginRO<CenterMineUserDetailRO>> miniAppLogin(@RequestBody ProviderLoginQO loginVO) {
        //需要手动赋值
        loginVO.setPlatform(PlatformType.mp);
        CenterLoginRO<CenterMineUserDetailRO> userDetailROUniLoginRO = centerLoginService.providerAndPhoneLogin(loginVO, null);
        return new ResultRO<>(userDetailROUniLoginRO);
    }

    /**
     * 不在使用
     * 这个是手机号直接绑定的
     *
     * @param bindPhoneVO
     * @return
     */
    @Deprecated
    @PostMapping("bindPhoneNum2")
    @ResponseBody
    public ResultRO<CenterMineUserDetailRO> bindPhoneNum2(@RequestBody BindPhoneVO bindPhoneVO) {
        CenterMineUserDetailRO centerMineUserDetailRO = centerPhoneNumService.userBindPhoneNum(bindPhoneVO);
        return new ResultRO<>(centerMineUserDetailRO);
    }
}
